//axios 封装
//请求拦截器
import Vue from 'vue'
import axios from 'axios';
import VueAxios from 'vue-axios';
import storage from "@/utils/storage";
import Qs from 'qs';

Vue.use(VueAxios, axios);

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    const token = storage.get('token');
    // config.headers['Accept'] = 'application/json';
    if(token){
        //配置header的token信息
        config.headers['Authorization'] = 'Bearer ' + token;
    }
    return config;
}, function (error) {
    return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    return response.data;
}, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});
// 定义基础路由
let base = '/manage';
let base_count = '/count';
// 大驼峰命名请求方法名称
//登录
export const Captcha = params => { return axios.get(`${base}/captcha`, params).then(res => res)};
export const UserLogin = params => { return axios.post(`${base}/login`, Qs.stringify(params)).then(res => res)};
//分类管理
export const CategoryList = params => { return axios.get(`${base}/category`, params).then(res => res)};
export const CategoryUpdate = params => { return axios.post(`${base}/category/update`, Qs.stringify(params)).then(res => res)};
export const CategoryDestroy = params => { return axios.post(`${base}/category/destroy`, Qs.stringify(params)).then(res => res)};
//管理员
export const OperateList = params => { return axios.get(`${base}/operate`, params).then(res => res)};
export const OperateAll = params => { return axios.get(`${base}/operate/all`, params).then(res => res)};
export const OperateUpdate = params => { return axios.post(`${base}/operate/update`, Qs.stringify(params)).then(res => res)};
export const OperateStatus= params => { return axios.post(`${base}/operate/status`, Qs.stringify(params)).then(res => res)};
export const OperateDestroy = params => { return axios.post(`${base}/operate/destroy`, Qs.stringify(params)).then(res => res)};
//角色
export const RoleList = params => { return axios.get(`${base}/role`, params).then(res => res)};
export const RoleAll = params => { return axios.get(`${base}/role/all`, params).then(res => res)};
export const RoleUpdate = params => { return axios.post(`${base}/role/update`, Qs.stringify(params)).then(res => res)};
export const RoleStatus= params => { return axios.post(`${base}/role/status`, Qs.stringify(params)).then(res => res)};
export const RoleDestroy = params => { return axios.post(`${base}/role/destroy`, Qs.stringify(params)).then(res => res)};
export const RoleAccess = params => { return axios.get(`${base}/role/access`, params).then(res => res)};
export const RoleAccessUpdate = params => { return axios.post(`${base}/role/store`, Qs.stringify(params)).then(res => res)};
//权限管理
export const NodeList = params => { return axios.get(`${base}/node`, params).then(res => res)};
export const NodeUpdate = params => { return axios.post(`${base}/node/update`, Qs.stringify(params)).then(res => res)};
export const NodeDestroy = params => { return axios.post(`${base}/node/destroy`, Qs.stringify(params)).then(res => res)};
//资源管理
export const ResourceList = params => { return axios.get(`${base}/resource`, params).then(res => res)};
export const ResourceDestroy = params => { return axios.post(`${base}/resource/destroy`, Qs.stringify(params)).then(res => res)};
//背景管理
export const BackList = params => { return axios.get(`${base}/back`, params).then(res => res)};
export const BackAll = params => { return axios.get(`${base}/back/all`, params).then(res => res)};
export const BackUpdate = params => { return axios.post(`${base}/back/update`, Qs.stringify(params)).then(res => res)};
export const BackDestroy = params => { return axios.post(`${base}/back/destroy`, Qs.stringify(params)).then(res => res)};

//春秋美文列表(params.params.activeName指的是页面选择的那个列表数据)
export const ArticleList = params => { return axios.get(`${base}/article/`, params).then(res => res)};
export const ArticleInfo = params => { return axios.get(`${base}/article/info`, params).then(res => res)};
export const ArticleUpdate = params => { return axios.post(`${base}/article/update`, Qs.stringify(params)).then(res => res)};
export const ArticleUpdateNew = params => { return axios.post(`${base}/article/update`, Qs.stringify(params)).then(res => res)};
export const ArticleStatus= params => { return axios.post(`${base}/article/status`, Qs.stringify(params)).then(res => res)};
export const ArticleDestroy = params => { return axios.post(`${base}/article/destroy`, Qs.stringify(params)).then(res => res)};
export const ArticlePreview = params => { return axios.post(`${base}/article/preview`, Qs.stringify(params)).then(res => res)};
export const setUpper = params => { return axios.post(`${base}/article/status`, Qs.stringify(params)).then(res => res)};

//视频
export const VideoList = params => { return axios.get(`${base}/video`, params).then(res => res); };//视频列表
export const VideoDestroy = params => { return axios.post(`${base}/video/destroy`, Qs.stringify(params)).then(res => res); };//视频删除
export const VideoUpdate = params => { return axios.post(`${base}/video/update`, Qs.stringify(params)).then(res => res); };//视频更新
export const VideoPreview = params => { return axios.post(`${base}/video/preview`, Qs.stringify(params)).then(res => res)};
export const VideoStatus = params => { return axios.post(`${base}/video/status`, Qs.stringify(params)).then(res => res)};



//模板消息
export const MessageList = params => { return axios.get(`${base}/message`, params).then(res => res); };
export const MessageUpdate= params => { return axios.post(`${base}/message/update`, Qs.stringify(params)).then(res => res); };
export const MessagePush= params => { return axios.post(`${base}/message/push`, Qs.stringify(params)).then(res => res); };
export const MessageRecord = params => { return axios.get(`${base}/message/record`, params).then(res => res); };
export const reToken = params => { return axios.get(`${base}/message/token`, params).then(res => res); };  //重置token//配置管理

//配置管理
export const Config = params => { return axios.get(`${base}/config`, params).then(res => res); };//获取配置信息
export const ConfigUpdate = params => { return axios.post(`${base}/config/update`,  Qs.stringify(params)).then(res => res); }; //更新配置信息
export const ConfigDestory = params => { return axios.post(`${base}/config/destroy`, Qs.stringify(params)).then(res => res); };//配置删除

//统计
export const getCount = params => { return axios.get(`${base}/count`, params).then(res => res); };//获取配置信息

//公众号链接
export const WechatList = params => { return axios.get(`${base}/wechat`, params).then(res => res); };//公众号链接列表
export const WechatDestroy = params => { return axios.post(`${base}/wechat/destroy`, Qs.stringify(params)).then(res => res); };//公众号链接删除
export const WechatUpdate = params => { return axios.post(`${base}/wechat/update`, Qs.stringify(params)).then(res => res); };//公众号链接更新
export const WechatPreview = params => { return axios.post(`${base}/wechat/preview`, Qs.stringify(params)).then(res => res); };//公众号链接预览


//小程序
export const AppletList = params => { return axios.get(`${base}/applet`, params).then(res => res)};//小程序列表
export const AppletUpdate = params => { return axios.post(`${base}/applet/update`, Qs.stringify(params)).then(res => res)};//小程序更新

// 微信客服
export const customList = params => { return axios.get(`${base}/custom`, params).then(res => res)};
export const customUpdate = params => { return axios.post(`${base}/custom/update`, Qs.stringify(params)).then(res => res)};
export const customDestory = params => { return axios.post(`${base}/custom/destroy`, Qs.stringify(params)).then(res => res)};

// 统计
export const AppletListAll = params => { return axios.get(`${base}/applet/list`, params).then(res => res)};
export const AppletCountVisites = params => { return axios.get(`${base_count}/visit`, params).then(res => res)};
export const AppletCountForm = params => { return axios.get(`${base_count}/form`, params).then(res => res)};
export const AppletCountBtn = params => { return axios.get(`${base_count}/btn`, params).then(res => res)};
export const AppletCountTpl = params => { return axios.get(`${base_count}/tpl`, params).then(res => res)};
export const AppletCountShare = params => { return axios.get(`${base_count}/share`, params).then(res => res)};
export const AppletCountBtnList = params => { return axios.get(`${base_count}/btn/list`, params).then(res => res)};
export const AppletCountBtnUpdate = params => { return axios.post(`${base_count}/btn/update`, Qs.stringify(params)).then(res => res)};

export const PhotoBingBingList = params => { return axios.get(`${base}/photo/bingbing`, params).then(res => res)};
export const PhotoBingBingUpdate = params => { return axios.post(`${base}/photo/bingbing`, Qs.stringify(params)).then(res => res)};














